from datetime import datetime
from typing import Dict, Any, List, Optional
from uuid import uuid4

from .models import Role


MESSAGES: Dict[str, List[Dict[str, Any]]] = {
	"user": [],
	"sales": [],
	"supplier": []
}
ORDERS: Dict[str, Dict[str, Any]] = {}


def now_iso() -> str:
	return datetime.utcnow().isoformat() + "Z"


def push_message(target_role: Role, msg_type: str, content: str, extra: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
	message = {
		"id": uuid4().hex,
		"role": target_role,
		"type": msg_type,
		"content": content,
		"extra": extra or {},
		"timestamp": now_iso(),
	}
	MESSAGES[target_role].append(message)
	return message


